﻿namespace Devonline.Entity;

/// <summary>
/// 数据加密业务抽象基类
/// 字符串类型的默认基类
/// </summary>
public abstract class EntitySetWithDataCipher : EntitySetWithDataCipher<string>, IDataCipher, IEntitySet, IEntitySetWithCreate
{
    /// <summary>
    /// 构造方法给 Id 赋值
    /// </summary>
    public EntitySetWithDataCipher() => Id = KeyGenerator.GetStringKey();
}

/// <summary>
/// 数据加密业务抽象基类
/// </summary>
public abstract class EntitySetWithDataCipher<TKey> : EntitySetWithCreate<TKey>, IDataCipher, IEntitySet<TKey>, IEntitySetWithCreate<TKey> where TKey : IConvertible
{
    /// <summary>
    /// 数据版本号, 用于给数据增加一个变量, 在计算 Hash 值时增加不确定因素
    /// </summary>
    [Column("version"), DisplayName("数据版本号"), Required, MaxLength(36), Excel]
    public virtual string Version { get; set; } = null!;
    /// <summary>
    /// 数据 Hash 值, 用于确认数据是否被篡改
    /// </summary>
    [Column("hash_code"), DisplayName("数据哈希值"), Required, MaxLength(64), Excel]
    public virtual string HashCode { get; set; } = null!;
    /// <summary>
    /// 数据密文, 数据被用户数据密钥加密后的结果
    /// </summary>
    [Column("ciphertext"), DisplayName("数据密文"), Required, MaxLength(4096), Excel]
    public virtual string Ciphertext { get; set; } = null!;
}